package com.yonyou.cms.epc.controller.graphic;
import com.yonyou.cms.epc.client.dto.graphic.GraphicAssemblyInfoDTO;
import com.yonyou.cms.epc.mapper.file.FileMapper;
import com.yonyou.cms.epc.service.graphic.GraphicAssemblyInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * @author xh
 * @since 2022-06-09
 */
@RestController
@RequestMapping("/graphic/graphicAssemblyInfo")
public class GraphicAssemblyInfoController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(GraphicAssemblyInfoController.class);

    @Autowired
    public GraphicAssemblyInfoService graphicAssemblyInfoService;


    /**
     * 分页查询数据
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @GetMapping(value = "/getGraphicAssemblyList")
    public IPage<Map<String, Object>> getList(@RequestParam Map<String, Object> queryCondition,
                                                     Page<Map<String, Object>> page) {
        return graphicAssemblyInfoService.selectPageBysql(page, queryCondition);
    }
    /**
     * 进行数据修改
     * @param id 数据主键ID
     * @return  Map<String,Object> 数据对应的map 结构
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @GetMapping(value="/{id}")
    @SuppressWarnings("unchecked")
    public Map<String,Object> getById(@PathVariable("id") Integer id) {
        return graphicAssemblyInfoService.getById(id);
    }

    /**
     * 进行数据新增
     * @param graphicAssemblyInfoDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String,Object> insert(@RequestBody GraphicAssemblyInfoDTO graphicAssemblyInfoDTO) {
        logger.debug("graphicAssemblyInfoDTO:{}",graphicAssemblyInfoDTO);
        return graphicAssemblyInfoService.insert( graphicAssemblyInfoDTO);
    }

    /**
     * 进行数据修改
     * @param graphicAssemblyInfoDTO 需要保存的DTO
     * @return Map<String,Object> 返回的数据map
     * @author xh
     * @since 2022-06-09
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> update(@RequestBody GraphicAssemblyInfoDTO graphicAssemblyInfoDTO) {
        return graphicAssemblyInfoService.update(graphicAssemblyInfoDTO);
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateGraphicAssembly", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object>  updateAppintmentInfo(@RequestBody GraphicAssemblyInfoDTO graphicAssemblyInfoDTO) {
        return graphicAssemblyInfoService.updateAppintmentInfo(graphicAssemblyInfoDTO);
    }

    /**
     * 根据id删除对象
     * @param id 需要修改数据的ID
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @PostMapping(value = "/deleteById/{id}")
    public boolean deleteById(@PathVariable("id") Integer id){
        logger.debug("删除ID:{}",id);
        if(id>0){
            graphicAssemblyInfoService.deleteById(id);
        }
        return true;
    }

    /**
     * 根据IDs批量删除对象
     * @param ids 需要修改数据的ID集合
     * @author xh
     * @since 2022-06-09
     */
    @DeleteMapping(value="/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids){
        logger.debug("删除ID:{}",ids);
        graphicAssemblyInfoService.deleteBatchIds(ids);
        return true;
    }

    /**
     * 进行下拉框查询(一级代码)
     * @param
     * @return  ListMap<String,Object> 数据对应的List 结构
     * @author xh
     * @since 2022-06-09
     */
    @RequestMapping(value = "/getMenuLevelList", method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String, Object>> getMenuLevelList(@RequestParam Map<String, Object> params) {
        //    Map<String, Object> queryCondition=new HashMap<>();
        return graphicAssemblyInfoService.selectListBySql(params);
    }

    /**
     * 图解目录批量导入
     * @param datas
     * @return Map
     * @author xh
     * @since 2022/6/21
     */
    @ResponseBody
    @PostMapping("imports")
    @ResponseStatus(HttpStatus.CREATED)
    public Map<String, Object> imports(@RequestBody List<Map<String, Object>> datas) {
        logger.info("批量导入图解目录:{}", datas);
        return graphicAssemblyInfoService.imports(datas);
    }
    /**
     * 查询备件图片
     * @param map
     * @return List<Map>
     * @author xh
     * @since 2022/6/27
     */

    @ResponseBody
    @GetMapping("/getfilelist")
    public List<Map<String, Object>> getfilelist(@RequestParam Map<String, Object> map) {
        return graphicAssemblyInfoService.getfilelist(map);
    }


    /**
     * 删除图片文件
     *
     * @return
     * @author xuhang
     * @since 2022-06-30
     */
    @ResponseBody
    @PostMapping("/deleteZcPicFile")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "删除总层图片文件")
    public int deletePartPicFile(@RequestBody Map<String, Long> map) {
        return graphicAssemblyInfoService.deleteZcPicFile(map);
    }

    /**
     * 分页查询图解物料数据
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author xh
     * @since 2022-06-09
     */
    @ResponseBody
    @GetMapping(value = "/selectgraphicAndAssemblyInfoPage")
    public IPage<Map<String, Object>> getGraphicAndAssemblyList(@RequestParam Map<String, Object> queryCondition,
                                              Page<Map<String, Object>> page) {
        return graphicAssemblyInfoService.selectgraphicAndAssemblyInfoPage(page, queryCondition);
    }

    /**
     * 分页查询备件基础信息
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author xh
     * @since 2022-07-07
     */
    @ResponseBody
    @GetMapping(value = "/selectpartinfoPage")
    public IPage<Map<String, Object>> getPartinfoList(@RequestParam Map<String, Object> queryCondition,
                                                                Page<Map<String, Object>> page) {
        return graphicAssemblyInfoService.selectpartinfoPage(page, queryCondition);
    }

    /**
     * 图解目录批量导入升级版
     * @param datas
     * @return Map
     * @author xh
     * @since 2022/7/25
     */
    @ResponseBody
    @PostMapping("importsUpgrade")
    @ResponseStatus(HttpStatus.CREATED)
    public Map<String, Object> importsUpgrade(@RequestBody List<Map<String, Object>> datas) {
        logger.info("批量导入图解目录:{}", datas);
        return graphicAssemblyInfoService.importsUpgrade(datas);
    }


}